package com.zhilianbao.leyaogo.ui.adapter.home;

import android.content.Context;
import android.view.ViewGroup;

import com.bql.baseadapter.recycleView.QuickRcvAdapter;
import com.bql.baseadapter.recycleView.QuickRcvHolder;
import com.bql.utils.CheckUtils;
import com.zhilianbao.leyaogo.R;
import com.zhilianbao.leyaogo.listener.OnAddToCartClickListener;
import com.zhilianbao.leyaogo.model.response.home.SpecialActivityInfo;
import com.zhilianbao.leyaogo.utils.ImageUtils;
import com.zhilianbao.leyaogo.utils.Utils;
import com.zhilianbao.leyaogo.view.widgets.MoneyTextView;

import java.util.List;

/**
 * ClassName: SpecialActivityListAdapter <br>
 * Description: 活动详情列表样式Adapter<br>
 * Author: Cyarie <br>
 * Created: 2016/12/12 18:27 <br>
 * Update Time：<br>
 * Update Description：<br>
 */
public class SpecialActivityListAdapter extends QuickRcvAdapter<SpecialActivityInfo.MallActivityGoodsSignVoListBean.ActivityGoodsListBean> {

    private OnAddToCartClickListener mOnAddToCartClickListener;

    //活动类型 0 专题 显示标签 否则不显示
    private int activityType;

    public SpecialActivityListAdapter(Context context, List<SpecialActivityInfo.MallActivityGoodsSignVoListBean.ActivityGoodsListBean> data, OnAddToCartClickListener mOnAddToCartClickListener) {
        super(context, data, R.layout.item_special_activity_list);
        this.mOnAddToCartClickListener = mOnAddToCartClickListener;
    }

    @Override
    protected void bindDataHelper(QuickRcvHolder viewHolder, int position, SpecialActivityInfo.MallActivityGoodsSignVoListBean.ActivityGoodsListBean item) {
        ViewGroup.LayoutParams layoutParams = viewHolder.getView(R.id.iv_goods).getLayoutParams();
        layoutParams.height = layoutParams.width = (Utils.getScreenWidth() - Utils.dp2px(4) * 3) / 2;
        viewHolder.getView(R.id.iv_goods).setLayoutParams(layoutParams);
        ImageUtils.loadGoodsPic(Utils.returnUrlShow(item.getGoodsPic()), viewHolder.getView(R.id.iv_goods));
        viewHolder.setText(R.id.tv_goods_name, item.getGoodsName());
        if (activityType == 0) {
            viewHolder.setVisible(R.id.rv_label, !CheckUtils.isEmpty(item.getGoodsActivitySign()));
            viewHolder.setText(R.id.rv_label, !CheckUtils.isEmpty(item.getGoodsActivitySign()) ? item.getGoodsActivitySign() : "");
        }
        if (item.getGoodsType() == 1 && item.getGoodsSkuId() != 0) {
            //            ((MoneyTextView) viewHolder.getView(R.id.tv_account_price)).setAmount(item.getSkuPrice());
            //            ((MoneyTextView) viewHolder.getView(R.id.tv_origin_price)).setAmount(item.getSkuMPrice());
            viewHolder.setText(R.id.tv_goods_desc, item.getItemVals());
        } else {
            //            ((MoneyTextView) viewHolder.getView(R.id.tv_account_price)).setAmount(item.getPrice());
            //            ((MoneyTextView) viewHolder.getView(R.id.tv_origin_price)).setAmount(item.getMPrice());
            viewHolder.setText(R.id.tv_goods_desc, item.getGoodsDesc());
        }


        //折扣商品
        if (item.getPriceType() == 1) {
            if (item.getGoodsType() == 1 && item.getGoodsSkuId() != 0) {
                ((MoneyTextView) viewHolder.getView(R.id.tv_account_price)).setAmount(Utils.calculateAccountPrice(item.getSkuPrice(), item.getPrice()));
            } else {
                ((MoneyTextView) viewHolder.getView(R.id.tv_account_price)).setAmount(Utils.calculateAccountPrice(item.getGoodsPrice(), item.getPrice()));
            }
        } else {
            ((MoneyTextView) viewHolder.getView(R.id.tv_account_price)).setAmount(item.getPrice());
        }
        viewHolder.getView(R.id.iv_add_cart).setOnClickListener(v -> {

                    if (mOnAddToCartClickListener != null)
                        mOnAddToCartClickListener.onAddToCartClick(item, viewHolder.getView(R.id.iv_goods));


                }


        );
    }

    public void setActivityType(int activityType) {
        this.activityType = activityType;
    }
}
